/**
 * 应用基础视图
 */
define(['jquery', 'underscore', 'RootView', 'fileupload'],
    function($, _, RootView) {
        var DetailView = RootView.extend({
            el: 'body',
            events: {
                'click      [data-dismiss="file"]':'dismissFileLine'
            },
            initialize: function() {
                var selectedImgTpl = _.template(
                    '<tr class="new">'+
                        '<td class="fileimg"><img src="/uploads/<%= filename %>" alt="<%= originalname %>"></td>'+
                        '<td class="filename">'+
                            '<%= originalname %>'+
                            '<input type="hidden" name="pictures" value="<%= filename %>">'+
                        '</td>'+                  
                        '<td>'+
                            '<button data-dismiss="file" class="btn btn-danger" type="button"><i class="ion-trash-b"></i> 移除 </button>'+
                        '</td>'+
                    '</tr>');

                $('#fileupload').fileupload({
                        url: '/backend/serie/picture',
                        dataType: 'json',
                        done: function(e, data) {
                            var filename = data.result.filename;
                            var originalname = data.result.originalname;
                            $('#files').append(selectedImgTpl({
                                filename: filename,
                                originalname: originalname
                            }));
                        },
                        progressall: function(e, data) {
                            // var progress = parseInt(data.loaded / data.total * 100, 10);
                            // $('#progress .progress-bar').css(
                            //     'width',
                            //     progress + '%'
                            //     );
                        }
                    }).prop('disabled', !$.support.fileInput)
                    .parent().addClass($.support.fileInput ? undefined : 'disabled');
            },
            dismissFileLine:function(event){
                var $target = $(event.target),
                    $fileLine = $target.closest('tr');
                    
                    $fileLine.remove();
                    
            }
        });
        return DetailView;
    });